(function($) {
	function BackTop(el, opts) {
		this.opts = $.extend({}, BackTop.DEFAULTS, opts);
		this.$el = $('html,body');
		this.$target = $(el)		
		
		this.$target.on('click', function() {			
			if(this.opts.mode == 'move') {
				this.move()
			} else {
				this.go()
			}
		}.bind(this))
	}

	BackTop.prototype.move = function() {
		var opts = this.opts
		if($(window).scrollTop() != opts.dest && !this.$el.is(':animated')) {
			this.$el.animate({
				scrollTop: opts.dest
			}, opts.speed)
		}

	}
	BackTop.prototype.go = function() {
		var dest = this.opts.dest
		if($(window).scrollTop() != dest) {
			this.$el.scrollTop(dest)
		}

	}
	BackTop.DEFAULTS = {
		mode: 'move',
		dest: 0,
		speed: 500
	}

	$.fn.extend({
		backtop: function(opts) {
			this.each(function() {
				return new BackTop(this, opts)
			})
		}
	})

})(jQuery)